package com.woniu.springboot.product.controller;

import com.alibaba.csp.sentinel.annotation.SentinelResource;
import com.woniu.springboot.product.blockException.CustomException;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author zhaolei
 * @date 2021/5/12 - 0:07
 */
@RestController
@RequestMapping(value = "/hi")
public class HelloController {
    @GetMapping(value = "/hello")
    public String hello(){
        return "123";
    }

    @GetMapping(value = "/haha/{id}")
    @SentinelResource(value = "haha",fallback = "error2",blockHandlerClass = CustomException.class
                        ,blockHandler = "error3")
    public String haha(@PathVariable Integer id){
        if (id == 2) {
            throw new IllegalArgumentException("非法参数异常");
        }else if (id > 10 && id < 15) {
            throw new NullPointerException("404 NOT FOUND");
        }else {
            return "ok";
        }
//        return "22";
    }
    public static String error2(@PathVariable Integer id,Throwable throwable){
        return "出现了" + throwable.getMessage();
    }
}
